{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import _pickle as cPickle\n",
    "from collections import defaultdict"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取推荐列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defaultdict(dict,\n",
       "            {'australia': {0: ['0099771519',\n",
       "               '1857022424',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558'],\n",
       "              1: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              2: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              3: ['0552998486',\n",
       "               '015602943X',\n",
       "               '0552140295',\n",
       "               '0440220602',\n",
       "               '0446532231',\n",
       "               '0007170866',\n",
       "               '1875989218',\n",
       "               '0099727412',\n",
       "               '0860074382',\n",
       "               '0140008535',\n",
       "               '0385335482',\n",
       "               '0553279556',\n",
       "               '1400034779',\n",
       "               '0743225082',\n",
       "               '0949206318',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883'],\n",
       "              4: ['0091867770',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600'],\n",
       "              5: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078']},\n",
       "             'canada': {0: ['0140505865',\n",
       "               '0140067477',\n",
       "               '076790592X',\n",
       "               '0553250426',\n",
       "               '0060392452',\n",
       "               '0676974791',\n",
       "               '080410526X',\n",
       "               '1552783081',\n",
       "               '0446350982',\n",
       "               '038079487X',\n",
       "               '0385505833',\n",
       "               '0676972152',\n",
       "               '0786867647',\n",
       "               '0060959037',\n",
       "               '0771099894',\n",
       "               '0812550706',\n",
       "               '0425122123',\n",
       "               '0446667900',\n",
       "               '0671011375',\n",
       "               '1550541129'],\n",
       "              1: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              2: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              3: ['0060915544',\n",
       "               '0140042393',\n",
       "               '0552137030',\n",
       "               '0836220889',\n",
       "               '0425105334',\n",
       "               '0836218256',\n",
       "               '0140277439',\n",
       "               '0345338588',\n",
       "               '1853260002',\n",
       "               '0060935464',\n",
       "               '0836218353',\n",
       "               '0671868691',\n",
       "               '0446532231',\n",
       "               '038542017X',\n",
       "               '0440224764',\n",
       "               '0770422578',\n",
       "               '0006485278',\n",
       "               '0451163524',\n",
       "               '0771060548',\n",
       "               '0553287893'],\n",
       "              4: ['0380718839',\n",
       "               '0316666343',\n",
       "               '0345370775',\n",
       "               '0684872153',\n",
       "               '0671758896',\n",
       "               '0676974805',\n",
       "               '0440213525',\n",
       "               '0515111279',\n",
       "               '034540288X',\n",
       "               '0676973094',\n",
       "               '0671027360',\n",
       "               '0684874350',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344'],\n",
       "              5: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078']},\n",
       "             'france': {0: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              1: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              2: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              3: ['2070370003',\n",
       "               '2070408507',\n",
       "               '2253140872',\n",
       "               '2266084372',\n",
       "               '2877302202',\n",
       "               '22530152730',\n",
       "               '2070744833',\n",
       "               '2253072079',\n",
       "               '2277260029',\n",
       "               '2290302155',\n",
       "               '2070363317',\n",
       "               '2253153265',\n",
       "               '2253144452',\n",
       "               '2264016124',\n",
       "               '2226135022',\n",
       "               '2020306492',\n",
       "               '2253154393',\n",
       "               '2290308285',\n",
       "               '2253150711',\n",
       "               '229030039X'],\n",
       "              4: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              5: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078']},\n",
       "             'germany': {0: ['3518366823',\n",
       "               '3423072571',\n",
       "               '3518368540',\n",
       "               '3423203668',\n",
       "               '3426029553',\n",
       "               '3453007867',\n",
       "               '3404148665',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059'],\n",
       "              1: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              2: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              3: ['3551551936',\n",
       "               '3551551693',\n",
       "               '3551551677',\n",
       "               '3423071516',\n",
       "               '3518372742',\n",
       "               '3257230478',\n",
       "               '3442727952',\n",
       "               '3442724686',\n",
       "               '3518100734',\n",
       "               '3596215226',\n",
       "               '3150000017',\n",
       "               '3426612704',\n",
       "               '3423205202',\n",
       "               '3499224615',\n",
       "               '3423202947',\n",
       "               '3442442354',\n",
       "               '3453071174',\n",
       "               '3551551685',\n",
       "               '3423204206',\n",
       "               '3518388762'],\n",
       "              4: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              5: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078']},\n",
       "             'italy': {0: ['8806142100',\n",
       "               '8826703132',\n",
       "               '884590184X',\n",
       "               '8817131628',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706'],\n",
       "              2: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              3: ['8845205118',\n",
       "               '8807813823',\n",
       "               '8845915700',\n",
       "               '8817106259',\n",
       "               '8807701510',\n",
       "               '8807816067',\n",
       "               '881786983X',\n",
       "               '0743222229',\n",
       "               '8807817039',\n",
       "               '8807814684',\n",
       "               '8806161741',\n",
       "               '884541096X',\n",
       "               '8845290077',\n",
       "               '8817106100',\n",
       "               '0451164075',\n",
       "               '8807816059',\n",
       "               '8804342838',\n",
       "               '9770390107900',\n",
       "               '1844262553',\n",
       "               '0439139597'],\n",
       "              4: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              5: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078']},\n",
       "             'n/a': {0: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              3: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              4: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078']},\n",
       "             'other': {0: ['8826703132',\n",
       "               '0060008024',\n",
       "               '0439064872',\n",
       "               '1558743669',\n",
       "               '0440211727',\n",
       "               '0330332775',\n",
       "               '0140298479',\n",
       "               '0380789019',\n",
       "               '034536676X',\n",
       "               '0446679593',\n",
       "               '0316693251',\n",
       "               '0316693006',\n",
       "               '1400034779',\n",
       "               '0345337662',\n",
       "               '0375706771',\n",
       "               '0385335881',\n",
       "               '0345339681',\n",
       "               '0553296981',\n",
       "               '044651652X',\n",
       "               '0062502182'],\n",
       "              1: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              2: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              3: ['0553296981',\n",
       "               '0441001971',\n",
       "               '0590353403',\n",
       "               '0671793489',\n",
       "               '0553213148',\n",
       "               '0515131229',\n",
       "               '0446310786',\n",
       "               '0439139597',\n",
       "               '0345378490',\n",
       "               '0747546290',\n",
       "               '0842329218',\n",
       "               '0312924585',\n",
       "               '3257228007',\n",
       "               '0786868716',\n",
       "               '051513628X',\n",
       "               '0151008116',\n",
       "               '0061092177',\n",
       "               '0375702709',\n",
       "               '0099800403',\n",
       "               '0439136350'],\n",
       "              4: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              5: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078']},\n",
       "             'portugal': {0: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              1: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              2: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              3: ['038082101X',\n",
       "               '0439139600',\n",
       "               '0380815923',\n",
       "               '006050918X',\n",
       "               '9505156944',\n",
       "               '0380977788',\n",
       "               '002542730X',\n",
       "               '0460877305',\n",
       "               '0385721234',\n",
       "               '0385413041',\n",
       "               '9726081378',\n",
       "               '0811214982',\n",
       "               '0330262130',\n",
       "               '0880381744',\n",
       "               '0552137030',\n",
       "               '9722113747',\n",
       "               '9580464162',\n",
       "               '9724614565',\n",
       "               '1401201385',\n",
       "               '1844262553'],\n",
       "              4: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              5: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078']},\n",
       "             'spain': {0: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              1: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              2: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              3: ['8445071416',\n",
       "               '8420616893',\n",
       "               '8420613487',\n",
       "               '950491036X',\n",
       "               '8478886508',\n",
       "               '8478886451',\n",
       "               '0156013924',\n",
       "               '8408039369',\n",
       "               '8420636282',\n",
       "               '8495501074',\n",
       "               '8420432113',\n",
       "               '8440627203',\n",
       "               '8445071408',\n",
       "               '0452282152',\n",
       "               '9681501225',\n",
       "               '8445071769',\n",
       "               '8420466034',\n",
       "               '8445071394',\n",
       "               '8423309223',\n",
       "               '8433914545'],\n",
       "              4: ['8408043641',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600'],\n",
       "              5: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078']},\n",
       "             'united kingdom': {0: ['0590660543',\n",
       "               '000649840X',\n",
       "               '0330367358',\n",
       "               '0330376519',\n",
       "               '1857027051',\n",
       "               '0749395990',\n",
       "               '0552124753',\n",
       "               '0099771519',\n",
       "               '0749399902',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207'],\n",
       "              1: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              2: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078'],\n",
       "              3: ['1844262553',\n",
       "               '0091891965',\n",
       "               '0140620117',\n",
       "               '0330258648',\n",
       "               '1860465811',\n",
       "               '1857231384',\n",
       "               '0552145424',\n",
       "               '0440206154',\n",
       "               '0552131059',\n",
       "               '0192833596',\n",
       "               '0440235596',\n",
       "               '0552142379',\n",
       "               '0330267388',\n",
       "               '0671024337',\n",
       "               '0380002930',\n",
       "               '0722532938',\n",
       "               '0552149519',\n",
       "               '0140287248',\n",
       "               '0380813815',\n",
       "               '0064407667'],\n",
       "              4: ['1844262553',\n",
       "               '0552147680',\n",
       "               '0552131067',\n",
       "               '0552996181',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706'],\n",
       "              5: ['1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558',\n",
       "               '0439139600',\n",
       "               '0440219078']},\n",
       "             'usa': {0: ['0156004801',\n",
       "               '0060256672',\n",
       "               '0971942315',\n",
       "               '1576738167',\n",
       "               '0553351397',\n",
       "               '0441002935',\n",
       "               '0615116426',\n",
       "               '0316735027',\n",
       "               '0140309578',\n",
       "               '0140185232',\n",
       "               '0553148001',\n",
       "               '0395977894',\n",
       "               '0743455967',\n",
       "               '0618002235',\n",
       "               '039480029X',\n",
       "               '0877738513',\n",
       "               '0060248025',\n",
       "               '0807083054',\n",
       "               '0553380958',\n",
       "               '0553213504'],\n",
       "              1: ['0064407667',\n",
       "               '0439064872',\n",
       "               '059035342X',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605'],\n",
       "              2: ['0590353403',\n",
       "               '0440237688',\n",
       "               '0451191137',\n",
       "               '0439139597',\n",
       "               '0679886370',\n",
       "               '0140348107',\n",
       "               '0064472272',\n",
       "               '0439064864',\n",
       "               '0671027344',\n",
       "               '0446608955',\n",
       "               '0394820371',\n",
       "               '0385729332',\n",
       "               '0316666343',\n",
       "               '0385729340',\n",
       "               '0385730586',\n",
       "               '043935806X',\n",
       "               '0439136350',\n",
       "               '1576738159',\n",
       "               '0440439884',\n",
       "               '0345342968'],\n",
       "              3: ['0066238501',\n",
       "               '0517693119',\n",
       "               '0394800389',\n",
       "               '0920668364',\n",
       "               '0395177111',\n",
       "               '0890876789',\n",
       "               '0898159954',\n",
       "               '0316286850',\n",
       "               '0375503803',\n",
       "               '0316779059',\n",
       "               '156402976X',\n",
       "               '0553110845',\n",
       "               '0060256737',\n",
       "               '0060968966',\n",
       "               '0670451932',\n",
       "               '0805013407',\n",
       "               '0060961325',\n",
       "               '0140195831',\n",
       "               '0451525663',\n",
       "               '0451171926'],\n",
       "              4: ['0312303467',\n",
       "               '0060514957',\n",
       "               '0553377868',\n",
       "               '0688167888',\n",
       "               '0399151451',\n",
       "               '1579546463',\n",
       "               '0380977311',\n",
       "               '0553379615',\n",
       "               '0943233828',\n",
       "               '0446532452',\n",
       "               '0553565079',\n",
       "               '0066214769',\n",
       "               '0446322180',\n",
       "               '0439064864',\n",
       "               '0399151613',\n",
       "               '0449911519',\n",
       "               '0451169514',\n",
       "               '0553802461',\n",
       "               '0312983220',\n",
       "               '0312983301'],\n",
       "              5: ['0440234743',\n",
       "               '044022165X',\n",
       "               '1844262553',\n",
       "               '0439139597',\n",
       "               '0439136350',\n",
       "               '0439064864',\n",
       "               '0877017883',\n",
       "               '0618002227',\n",
       "               '0590353403',\n",
       "               '0671027344',\n",
       "               '0385199570',\n",
       "               '0771060548',\n",
       "               '0156528207',\n",
       "               '0618129022',\n",
       "               '0552131059',\n",
       "               '0811801802',\n",
       "               '0670032379',\n",
       "               '0812550706',\n",
       "               '0670894605',\n",
       "               '0811825558']}})"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_recommand = cPickle.load(open('./feature_recommand.pkl','rb'))\n",
    "feature_recommand"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 导入测试集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>location</th>\n",
       "      <th>age</th>\n",
       "      <th>item_id</th>\n",
       "      <th>rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>109814</th>\n",
       "      <td>27462</td>\n",
       "      <td>usa</td>\n",
       "      <td>0</td>\n",
       "      <td>1587492695</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>561359</th>\n",
       "      <td>137190</td>\n",
       "      <td>france</td>\n",
       "      <td>3</td>\n",
       "      <td>0552997234</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182843</th>\n",
       "      <td>42721</td>\n",
       "      <td>canada</td>\n",
       "      <td>3</td>\n",
       "      <td>0671024108</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>854047</th>\n",
       "      <td>208829</td>\n",
       "      <td>canada</td>\n",
       "      <td>0</td>\n",
       "      <td>0140503897</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>559003</th>\n",
       "      <td>136348</td>\n",
       "      <td>usa</td>\n",
       "      <td>4</td>\n",
       "      <td>0807220299</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        user_id location  age     item_id  rating\n",
       "109814    27462      usa    0  1587492695       0\n",
       "561359   137190   france    3  0552997234       8\n",
       "182843    42721   canada    3  0671024108       8\n",
       "854047   208829   canada    0  0140503897       0\n",
       "559003   136348      usa    4  0807220299       9"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data_text = cPickle.load(open('./df_data_text.pkl','rb'))\n",
    "df_data_text.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 344931 entries, 109814 to 473426\n",
      "Data columns (total 5 columns):\n",
      "user_id     344931 non-null int64\n",
      "location    344931 non-null object\n",
      "age         344931 non-null int32\n",
      "item_id     344931 non-null object\n",
      "rating      344931 non-null int32\n",
      "dtypes: int32(2), int64(1), object(2)\n",
      "memory usage: 13.2+ MB\n"
     ]
    }
   ],
   "source": [
    "df_data_text.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 处理location"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['australia',\n",
       " 'canada',\n",
       " 'france',\n",
       " 'germany',\n",
       " 'italy',\n",
       " 'n/a',\n",
       " 'other',\n",
       " 'portugal',\n",
       " 'spain',\n",
       " 'united kingdom',\n",
       " 'usa']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "top_location_s = list(feature_recommand.keys())\n",
    "top_location_s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "usa               230427\n",
       "canada             31331\n",
       "united kingdom     15239\n",
       "germany            11986\n",
       "                    8237\n",
       "                   ...  \n",
       "guam                   1\n",
       "rwanda                 1\n",
       "senegal                1\n",
       "nepal                  1\n",
       "belgium\"               1\n",
       "Name: location, Length: 240, dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data_text['location'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_data_text['location']=df_data_text['location'].apply(lambda location:location if location in top_location_s else 'other')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 得到准确率和召回率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "union_quantity = 0       # 为用户推荐的用户喜欢的个数\n",
    "recommand_quantity = 0   # 为用户推荐的个数\n",
    "user_fav_quantity = 0    # 用户喜欢的个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "执行到： australia 0\n",
      "执行到： australia 1\n",
      "执行到： australia 2\n",
      "执行到： australia 3\n",
      "执行到： australia 4\n",
      "执行到： australia 5\n",
      "执行到： canada 0\n",
      "执行到： canada 1\n",
      "执行到： canada 2\n",
      "执行到： canada 3\n",
      "执行到： canada 4\n",
      "执行到： canada 5\n",
      "执行到： france 0\n",
      "执行到： france 2\n",
      "执行到： france 3\n",
      "执行到： france 4\n",
      "执行到： france 5\n",
      "执行到： germany 0\n",
      "执行到： germany 1\n",
      "执行到： germany 2\n",
      "执行到： germany 3\n",
      "执行到： germany 4\n",
      "执行到： germany 5\n",
      "执行到： italy 0\n",
      "执行到： italy 2\n",
      "执行到： italy 3\n",
      "执行到： italy 4\n",
      "执行到： n/a 0\n",
      "执行到： other 0\n",
      "执行到： other 1\n",
      "执行到： other 2\n",
      "执行到： other 3\n",
      "执行到： other 4\n",
      "执行到： other 5\n",
      "执行到： portugal 0\n",
      "执行到： portugal 2\n",
      "执行到： portugal 3\n",
      "执行到： portugal 4\n",
      "执行到： portugal 5\n",
      "执行到： spain 0\n",
      "执行到： spain 2\n",
      "执行到： spain 3\n",
      "执行到： spain 4\n",
      "执行到： spain 5\n",
      "执行到： united kingdom 0\n",
      "执行到： united kingdom 1\n",
      "执行到： united kingdom 2\n",
      "执行到： united kingdom 3\n",
      "执行到： united kingdom 4\n",
      "执行到： united kingdom 5\n",
      "执行到： usa 0\n",
      "执行到： usa 1\n",
      "执行到： usa 2\n",
      "执行到： usa 3\n",
      "执行到： usa 4\n",
      "执行到： usa 5\n",
      "准确率： 0.0003806202422469719\n",
      "召回率： 0.0032610965638002216\n"
     ]
    }
   ],
   "source": [
    "for location,groupby_location in df_data_text.groupby('location'):\n",
    "    for age,groupby_location_age in groupby_location.groupby('age'):\n",
    "        print('执行到：',location,age)\n",
    "        for user_id,groupby_location_age_userid in groupby_location_age.groupby('user_id'):\n",
    "\n",
    "            items_rating = groupby_location_age_userid.groupby('item_id')['rating'].mean().sort_values(ascending=False)\n",
    "            user_fav_items = [\n",
    "                item_id\n",
    "                for item_id in items_rating.index if items_rating[item_id] >= 5\n",
    "            ]\n",
    "            recommand_items = feature_recommand[location][age]\n",
    "            union_quantity += len(\n",
    "                set(user_fav_items) & set(recommand_items)\n",
    "            )\n",
    "            recommand_quantity += len(recommand_items)\n",
    "            user_fav_quantity += len(user_fav_items)\n",
    "\n",
    "print('准确率：',union_quantity/recommand_quantity)\n",
    "print('召回率：',union_quantity/user_fav_quantity)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
